package org.vs.handler.responsibilitychain.vote;

import com.alibaba.fastjson2.JSON;
import org.springframework.stereotype.Component;
import org.vs.annotation.CheckBalance;
import org.vs.domain.vo.ProgressVO;
import org.vs.handler.responsibilitychain.BaseResponsibilityChainHandler;

import javax.annotation.Resource;

@Component
public class VotePublishTransmitUserInfoHandler extends BaseResponsibilityChainHandler {
    @Resource
    private VotePublishCompleteHandler votePublishCompleteHandler;

    @CheckBalance
    @Override
    protected boolean customerHandler(Object obj) {
        try {
            VotePublishHandlerEO votePublishHandlerEO = (VotePublishHandlerEO) obj;

            votePublishHandlerEO.setCount(votePublishHandlerEO.getCount() + 1);
            setHandler(votePublishCompleteHandler);
            setMessage(votePublishHandlerEO.getHashcode(), JSON.toJSONString(ProgressVO
                    .builder()
                    .progress((100 / voteCount) * votePublishHandlerEO.getCount())
                    .info("完成分发消息")
                    .build()));

            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }
}
